package com.steven.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
 * 字节流
 * 
 * inputStream，outputStream
 */
public class FileOutputStreamDemo {
	
	public static void main(String[] args) throws Exception {
		
//		writeFile();
		readFile2();
		
	}
	

	public static void readFile1() throws Exception{
		FileInputStream  fis=null ;
		try {
			   fis = new FileInputStream("fos.txt");
			   
			   int len =0;
			   byte[] buf = new byte[fis.available()];
			   
			    fis.read(buf);
			    	System.out.println(new String(buf ));
			     
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	

	public static void readFile2() throws Exception{
		FileInputStream  fis=null ;
		try {
			   fis = new FileInputStream("fos.txt");
			   
			   int ch=0;
			   
			    while ((ch=fis.read())!=-1){
			    	System.out.println((char)ch);
			    	
			    }
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	
	public static void readFile() throws Exception{
		FileInputStream  fis=null ;
		try {
			   fis = new FileInputStream("fos.txt");
			   
			   int len =0;
			   byte[] buf = new byte[1024];
			   
			    while ((len=fis.read(buf))!=-1){
			    	System.out.println(new String(buf,0,len));
			    	
			    }
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
public static void writeFile() throws IOException{
	FileOutputStream fos = null;
	try {
		fos = new FileOutputStream("fos.txt");
		fos.write("abcefg".getBytes());
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}finally{
		fos.close();
	}
	

	
}
	

}
